#include "progressbarwidget.h"
#include "widgets/uslider.h"
#include "widgets/uprogressbar.h"
#include <QVBoxLayout>

ProgressBarWidget::ProgressBarWidget(QWidget* parent) : UWidget(parent)
{
    setBackgroundRole(QPalette::Base);
    setRadius(8);

    auto p1 = new UProgressBar(this);
    p1->setRadius(5);
    p1->setProgressRole(UPalette::SuccessBackground);
    p1->setInvertedAppearance(true);
    p1->setFixedHeight(20);
    p1->setAlignment(Qt::AlignCenter);

    auto p2 = new UProgressBar(this);
    p2->setAlignment(Qt::AlignCenter);
    p2->setProgressRole(UPalette::WarningBackground);
    p2->setBorderWidth(4);
    p2->setBorderRole(UPalette::ModuleBackground);

    auto p3 = new UProgressBar(this);
    p3->setAlignment(Qt::AlignCenter);
    p3->setOrientation(Qt::Orientation::Vertical);
    p3->setProgressRole(UPalette::ErrorBackground);
    p3->setBorderRole(UPalette::ModuleBackground);
    p3->setRadius(10);
    p3->setBorderWidth(3);
    p3->setFixedHeight(500);

    auto p4 = new UProgressBar(this);
    p4->setOrientation(Qt::Orientation::Vertical);
    p4->setProgressRole(UPalette::OrangeBackground);
    p4->setInvertedAppearance(true);
    p4->setAlignment(Qt::AlignCenter);
    p4->setFixedHeight(500);

    auto hLayout = new QHBoxLayout;
    hLayout->addStretch();
    hLayout->addWidget(p3, 0, Qt::AlignHCenter);
    hLayout->addWidget(p4, 0, Qt::AlignHCenter);
    hLayout->addStretch();

    auto pSlider = new USlider(Qt::Orientation::Horizontal, this);
    pSlider->setRange(0, 100);
    connect(pSlider, &USlider::valueChanged, this, [p1, p3, p2, p4](int value)
    {
        p1->setValue(value);
        p2->setValue(value);
        p3->setValue(value);
        p4->setValue(value);
    });

    pSlider->setValue(60);

    auto mainLayout = new QVBoxLayout;
    mainLayout->addStretch();
    mainLayout->addWidget(p1);
    mainLayout->addWidget(p2);
    mainLayout->addLayout(hLayout);
    mainLayout->addWidget(pSlider);
    mainLayout->addStretch();
    setLayout(mainLayout);
}

ProgressBarWidget::~ProgressBarWidget()
{

}
